package utilsEx

import (
	"io"
	"net/http"
	"os"
)

//目前下载http,以后支持ftp等协议
func Download(url string, newfile string) error {
	imgUrl := url

	// Get the data
	resp, err := http.Get(imgUrl)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	// 创建一个文件用于保存
	out, err := os.Create(newfile)
	if err != nil {
		return err
	}
	defer out.Close()

	// 然后将响应流和文件流对接起来
	_, err = io.Copy(out, resp.Body)
	if err != nil {
		return err
	}
	return nil
}
